﻿using BasicData.Domain;
using BasicData.ErrorCode;
using BasicData.Infastruucture;
using BasicData.Read.API.application.Command.Permission;
using MediatR;

namespace BasicData.Read.API.application.CommandHandler.Permission
{
    public class FindPermissionTreeCommandHandler : IRequestHandler<FindPermissionTreeCommand, ApiResult<PermissionModel>>
    {
        private readonly IBaseRepository<PermissionModel> perRep;

        public FindPermissionTreeCommandHandler(IBaseRepository<PermissionModel> PerRep)
        {
            perRep = PerRep;
        }

        public Task<ApiResult<PermissionModel>> Handle(FindPermissionTreeCommand request, CancellationToken cancellationToken)
        {
            ApiResult<PermissionModel> res = new ApiResult<PermissionModel>();
            res.Code = BaseEnums.Success;
            res.Msg = "查询成功";

            var list = perRep.GetAll().Where(o => o.PermissionId == request.PermissionId).FirstOrDefault();
            res.Data = list;
            return Task.FromResult(res);
        }
    }
}
